<?php
	include "authenticate.php";
	include "logger.php";
	
//	echo $_POST["userLogin"];
	if($_POST["userLogin"] != "" && $_POST["userPassword"] != ""){
		// run information through authenticator
		if(authenticate($_POST["userLogin"],$_POST["userPassword"]))
		{
			Logger(null,0);			
			// authentication passed
			header("Location: ../index.php");
			
		}else {
			Logger($_POST['userLogin'],3);
			echo '<script>alert("Erro de usuario ou senha!");</script>';	
			echo '<script> window.location.href = "login.php";</script>';	
//			header("Location:login.php");
		}
	}
	else{
		unset($_SESSION['user'], $_SESSION['password'], $_SESSION['permissao']);
//		header("Location:login.php");
		echo '<script>alert("Digite o nome do usuario ou a senha!");</script>';	
		echo '<script> window.location.href = "login.php";</script>';	
	}

?>
